package com.sharkburner.aeris.service.article.impl;

import java.net.URL;
import java.util.List;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import org.springframework.stereotype.Component;

import com.sharkburner.aeris.bean.article.ArticleBean;
import com.sharkburner.aeris.bean.article.RssBean;
import com.sharkburner.aeris.service.article.ArticleReader;

/**
 * Rss Article Reader using JAXB
 * @author inartea
 *
 */
@Component("rssArticleReader")
public class RssArticleReader implements ArticleReader, Runnable {

	@Override
	public List<ArticleBean> getArticles(String rssURL) {
		RssBean rssBean=new RssBean();
		try {
			JAXBContext jaxbContext = JAXBContext.newInstance(RssBean.class);
			 
			Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
			rssBean=(RssBean) jaxbUnmarshaller.unmarshal(new URL(rssURL));
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		if(rssBean!=null){
			return rssBean.getArticleList();
		}

		return null;
	}

	@Override
	public void run() {
		// TODO Auto-generated method stub

	}

}
